package com.equipment;

import com.util.EncodingUtil;

/**
 * 参数设置请求幀A9
 * @version 1.18
 * @author 刘亚东
 *
 */
public class SetParameterRequest {

	private String STX = "55AA"; // 帧开始标志
	private String RSCTL = "00"; // 串口帧序列号
	private String Length = ""; // 长度
	private String code = "FD"; // 代码
	private String broadening = "C9"; // 扩展代码

	private String TxChannel = "";// 发射信道
	private String RxChannel = "";// 接受信道
	private String TxPower = "1F"; // 发射功率（十进制0-31）
	private String RxPower = "31";// 接收功率（十进制0-31）
	private String CRC = "00";// CRC（十进制0-1）
	private String BCC = ""; // 异或校验值


	private String BstNumber = "";// BST发送次数(长度1)
	private String BstInterval = "";// BST发送间隔(长度1)
	private String TrasferChannelNumber = "";// TrasferChannel发送次数(长度1)
	private String TrasferChannelInterval = ""; // TrasferChannel发送间隔(长度1)

	private String PsamNumForVersion1 = "";// 北京一版密钥PSAM卡号（1~4）(长度1)
	private String PsamNumForVersion2 = "";// 北京二版密钥PSAM卡号（1~4）(长度1)
	private String PsamNumForVersion3 = "";// 国标ESAM还原PSAM卡槽(长度1)
	private String PsamNumForVersion4 = "";// 国标交易PSAM卡槽(长度1)
	private String Expand = "00000000000000000000000000000000";//拓展信息 16字节

	/**
	 * 发送参数设置请求幀
	 *
	 * @return
	 */
	// ,String route
	public String command(String txChannel, String rxChannel, String txpower,
						  String rxpower, String Crc, String version1, String version2,
						  String number1, String interval1, String number2, String interval2,String version3,String version4) {
		try {
			this.PsamNumForVersion1 = EncodingUtil.desToHex(
					Integer.parseInt(version1), 2);
			this.PsamNumForVersion2 = EncodingUtil.desToHex(
					Integer.parseInt(version2), 2);
			this.PsamNumForVersion3 = EncodingUtil.desToHex(
					Integer.parseInt(version3), 2);
			this.PsamNumForVersion4 = EncodingUtil.desToHex(
					Integer.parseInt(version4), 2);
			this.TxChannel = EncodingUtil.desToHex(Integer.parseInt(txChannel),
					2);
			this.RxChannel = EncodingUtil.desToHex(Integer.parseInt(rxChannel),
					2);
			this.TxPower = EncodingUtil.desToHex(Integer.parseInt(txpower), 2);
			this.RxPower = EncodingUtil.desToHex(Integer.parseInt(rxpower), 2);
			this.CRC = EncodingUtil.desToHex(Integer.parseInt(Crc), 2);
			this.BstNumber = EncodingUtil
					.desToHex(Integer.parseInt(number1), 2);
			this.BstInterval = EncodingUtil.desToHex(
					Integer.parseInt(interval1), 2);
			this.TrasferChannelNumber = EncodingUtil.desToHex(Integer
					.parseInt(number2));
			this.TrasferChannelInterval = EncodingUtil.desToHex(
					Integer.parseInt(interval2), 2);
			Length = EncodingUtil.desToHex(
					(broadening + TxChannel + RxChannel + TxPower + RxPower
							+ CRC + BstNumber + BstInterval
							+ TrasferChannelNumber
							+ TrasferChannelInterval
							+ PsamNumForVersion1
							+ PsamNumForVersion2
							+ PsamNumForVersion3
							+ PsamNumForVersion4
							+ Expand
					).length() / 2, 4);
			String DATA = RSCTL + Length + code + broadening + TxChannel + RxChannel + TxPower + RxPower
					+ CRC + BstNumber + BstInterval
					+ TrasferChannelNumber
					+ TrasferChannelInterval
					+ PsamNumForVersion1
					+ PsamNumForVersion2
					+ PsamNumForVersion3
					+ PsamNumForVersion4
					+ Expand;

			// 异或校验从RSCTL到DATA所有字节的异或值TxPower+RxPower+CRC+
			BCC = EncodingUtil.yihuo(EncodingUtil.change(DATA));
			String retn = STX + DATA + BCC; // 拼接完整的请求
			return retn;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}

	}

	public String getSTX() {
		return STX;
	}

	public void setSTX(String sTX) {
		STX = sTX;
	}

	public String getRSCTL() {
		return RSCTL;
	}

	public void setRSCTL(String rSCTL) {
		RSCTL = rSCTL;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getBroadening() {
		return broadening;
	}

	public void setBroadening(String broadening) {
		this.broadening = broadening;
	}

	public String getBCC() {
		return BCC;
	}

	public void setBCC(String bCC) {
		BCC = bCC;
	}

	public String getLength() {
		return Length;
	}

	public void setLength(String length) {
		Length = length;
	}

	public String getPsamNumForVersion1() {
		return PsamNumForVersion1;
	}

	public void setPsamNumForVersion1(String psamNumForVersion1) {
		PsamNumForVersion1 = psamNumForVersion1;
	}

	public String getPsamNumForVersion2() {
		return PsamNumForVersion2;
	}

	public void setPsamNumForVersion2(String psamNumForVersion2) {
		PsamNumForVersion2 = psamNumForVersion2;
	}

	public String getBstNumber() {
		return BstNumber;
	}

	public void setBstNumber(String bstNumber) {
		BstNumber = bstNumber;
	}

	public String getBstInterval() {
		return BstInterval;
	}

	public void setBstInterval(String bstInterval) {
		BstInterval = bstInterval;
	}

	public String getTrasferChannelNumber() {
		return TrasferChannelNumber;
	}

	public void setTrasferChannelNumber(String trasferChannelNumber) {
		TrasferChannelNumber = trasferChannelNumber;
	}

	public String getTrasferChannelInterval() {
		return TrasferChannelInterval;
	}

	public void setTrasferChannelInterval(String trasferChannelInterval) {
		TrasferChannelInterval = trasferChannelInterval;
	}

}
